#define _CRT_SECURE_NO_WARNINGS 
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
	unsigned int N;
	cin >> N;
	vector<int>arr(N);                                  

	for (int i = 0; i < N; i++)
	{                       
		cin >> arr[i];
	}

	sort(arr.begin(), arr.end());

     int sum=0;

	for (auto x : arr)
	{
		/*sum += ((x - arr[N / 2]) > 0 ? (x - arr[N / 2]) : (arr[N / 2] - x));*/
		sum += abs(x - arr[N / 2]);
	}

	cout << sum<<endl;

	return 0;
}